package cn.icanci.basic;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @Author: icanci
 * @ProjectName: kangaroo-orm
 * @PackageName: cn.icanci.basic
 * @Date: Created in 2020/8/31 13:54
 * @ClassAction: 对 s_emp 的删除操作
 */
public class TestDeleteEmpData {
    public static void main(String[] args) {
        Connection conn = null;
        Statement statement = null;
        try {
            // 加载驱动
            Class.forName("com.mysql.cj.jdbc.Driver");
            // 连接数据库
            conn = DriverManager
                    .getConnection(
                            // 数据库地址
                            "jdbc:mysql://localhost:3306/kangaroo-orm?useSSL=false&serverTimezone=UTC",
                            // 数据库用户名
                            "root",
                            // 数据库密码
                            "root"
                    );
            // 编写SQL语句
            String sql = new String("delete from s_emp where id = 6").intern();
            // 创建执行SQL的对象
            statement = conn.createStatement();
            // 都是可以执行的
            // statement.executeUpdate(sql);
            statement.execute(sql);
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        } finally {
            if (null != statement) {
                try {
                    statement.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
            if (null != conn) {
                try {
                    conn.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
        }
    }
}
